from tkinter import *
from tkinter.messagebox import *
import random
from PIL import ImageTk, Image
from colorama import init
from summary import su

ts5: int = 0
ts4: int = 0
star5 = ["温迪", "刻晴", "莫娜", "七七", "迪卢克", "琴"]
star4 = ["砂糖", "诺艾尔", "雷泽", "辛焱", "迪奥娜", "重云", "班尼特", "菲谢尔", "凝光", "行秋", "北斗", "香菱", "芭芭拉", "弓藏", "祭礼弓", "绝弦",
         "风猎弓",
         "昭心", "祭礼残章", "流浪乐章", "匣里灭辰", "雨裁", "祭礼大剑", "钟剑", "西风大剑", "匣里龙吟", "祭礼剑", "笛剑", "西风剑"]
star3 = ["弹弓", "神射手之誓", "鸦羽弓", "翡玉法球", "讨龙英杰谭", "魔导绪论", "黑缨枪", "以理服人", "沐浴龙血的剑", "铁影阔剑", "飞天御剑", "黎明神剑", "冷刃"]
temp_arr = []


def star_appear(a: int):
    global ts4, ts5
    if a == 4:
        s4 = random.randint(0, star4.__len__() - 1)
        ts4 = 0
        ts5 = ts5 + 1
        temp_arr.append(star4[s4])
        showinfo(title="4Stars!", message="你得到了四星" + star4[s4])
    elif a == 3:
        s3 = random.randint(0, star3.__len__() - 1)
        showinfo(title="3Stars!", message="你得到了三星武器" + star3[s3])
        temp_arr.append(star3[s3])
        ts4 = ts4 + 1
        ts5 = ts5 + 1
    elif a == 5:
        s5 = random.randint(0, 5)
        ts4 = ts4 + 1
        ts5 = 0
        temp_arr.append(star5[s5])
        showinfo(title="5Stars!", message="你得到了五星" + star5[s5])


def wish():
    global ts4, ts5
    # 保底判定
    if ts4 == 9:
        star_appear(4)
        return 0
    if ts5 == 89:
        star_appear(5)
        return 0
    # 随机抽取
    star = random.randint(1, 1000)
    if 10 <= star <= 16:
        star_appear(5)
    elif 50 <= star <= 101:
        star_appear(4)
    else:
        star_appear(3)
    return 0


def wish10():
    for i in range(10):
        wish()


def sud():
    su(ts4, ts5, temp_arr)


def mw():
    # -------
    root = Tk()
    root.title("Genshin wish Simulator")
    background_image = Image.open(r"image/祈愿界面.png")
    background = ImageTk.PhotoImage(background_image)
    w = background.width()
    h = background.height()
    screenwidth = root.winfo_screenwidth()
    screenheight = root.winfo_screenheight()
    root.geometry("%dx%d+%d+%d" % (w, h, (screenwidth - w) / 2, (screenheight - h - 70) / 2))
    root.resizable(0, 0)
    init(autoreset=True)
    #  -------background

    background_label = Label(root, image=background)
    background_label.place(x=0, y=0, relwidth=1, relheight=1)
    background_label.pack()

    # -------button1
    button_image1 = PhotoImage(file="image/祈愿一次.png")
    button1 = Button(root, image=button_image1, command=wish)
    button1.place(x=610, y=575)
    # ---------button2
    button_image2 = PhotoImage(file="image/祈愿十次.png")
    button2 = Button(root, image=button_image2, command=wish10)
    button2.place(x=810, y=573)
    # -------
    button_image3 = PhotoImage(file="image/历史记录.png")
    button3 = Button(root, image=button_image3, command=sud)
    button3.place(x=240, y=593)
    root.mainloop()


if __name__ == "__main__":
    mw()
